package com.gduf.bbl.controller;

import java.util.Arrays;
import java.util.Map;


import com.gduf.bbl.common.utils.PageUtils;
import com.gduf.bbl.common.utils.R;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.gduf.bbl.entity.AddressEntity;
import com.gduf.bbl.service.AddressService;




/**
 * 
 *
 * @author xqw
 * @email 2041411595@qq.com
 * @date 2024-02-29 20:38:49
 */
@RestController
@CrossOrigin(allowCredentials = "true")
@RequestMapping("bbl/address")
public class AddressController {
    @Autowired
    private AddressService addressService;


    @ApiOperation(value = "根据用户id获取详细地址信息")
    @GetMapping("/getAddressByUserId")
    @ApiImplicitParam(type = "String",name = "userId",value = "用户id",required = true)
    public R getAddressByUserId(String userId){
        return addressService.getAddressByUserId(userId);

    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = addressService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		AddressEntity address = addressService.getById(id);

        return R.ok().put("address", address);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody AddressEntity address){
		addressService.save(address);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody AddressEntity address){
		addressService.updateById(address);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		addressService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
